package org.ecjmn.pringles.game;

import java.util.Collections;
import java.util.Iterator;
import java.util.Vector;

public class Deck {
	
	private Vector<Integer> thisDeck;
	
	public Deck() {
		thisDeck = new Vector<Integer>(); 
		for (int i=1; i<=4; i++) {
			for (int j=1; j<=13; j++) {
				thisDeck.add(j);
			}
		}
	}
	
	public int valueWithAIs1() {
		int valueSum = 0;
		 Iterator ita=thisDeck.iterator();
         while(ita.hasNext())
         {
               Integer intObj = (Integer)ita.next();
               valueSum += intObj.intValue();
         }
         return valueSum;
	}
	
	public int valueWithAIs11() {
		int valueSum = 0;
		 Iterator ita=thisDeck.iterator();
         while(ita.hasNext())
         {
               Integer intObj = (Integer)ita.next();
               if (intObj.intValue()==1){
            	   valueSum += 11;
               }
               else {
            	   valueSum += intObj.intValue();
               }
         }
         return valueSum;
	}
	
	public void shuffle() {
		Collections.shuffle(thisDeck);
	}
	
	public int pop() {
		int firstElement = thisDeck.firstElement();
		thisDeck.removeElementAt(0);
		return firstElement;
	}
	
	public Vector<Integer> getVector() {
		return thisDeck;
	}
	
	public void print() {
		System.out.println(thisDeck.toString());
	}
	
	// Sample
	public static void main(String[] arguments) {
		Deck deck = new Deck();
		deck.print();
		deck.shuffle();
		deck.print();
		System.out.println(deck.valueWithAIs1());
		System.out.println(deck.valueWithAIs11());
	}
	
	public int topValue() {
		return thisDeck.firstElement();
	}
}
